package com.ktjy.test;


import com.ktjy.entity.StorageRecord;
import com.ktjy.entity.Supplier;
import com.ktjy.entity.SysUser;
import com.ktjy.mapper.StorageMapper;
import com.ktjy.service.StorageService;
import com.ktjy.service.SupplierService;
import com.ktjy.service.SysUserService;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;
import java.util.List;

public class Main {
    Logger logger= LoggerFactory.getLogger(Main.class);
    @Test
    public void test() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService userService=(SysUserService) context.getBean("sysUserService");
        SysUser queryCondition=new SysUser();
        queryCondition.setRealName("李");
        queryCondition.setRoleId(2L);
        List<SysUser> userList=userService.getSysUserList(queryCondition);
        for (SysUser user:userList) {
            logger.info("SysUser : account={},realName={},roleName={}", user.getAccount(), user.getRealName(), user.getSysRole().getRoleName());
        }
    }
    @Test
    public void test2() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService userService=(SysUserService) context.getBean("sysUserService");
        SysUser user1=new SysUser();
        user1.setAccount("ceshi1");
        user1.setRealName("测试用户1");
        List<SysUser> userList= Arrays.asList(user1);
        userService.saveBatch(userList);
    }
    @Test
    public void test3() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService userService=(SysUserService) context.getBean("sysUserService");
        Integer count=userService.delete(10);
        if (count>0){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }
    }
    @Test
    public void test4() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService userService=(SysUserService) context.getBean("sysUserService");
        SysUser user1=new SysUser();
        user1.setId(11L);
        user1.setAccount("ceshi2");
        user1.setRealName("测试用户2");
        Integer count=userService.update(user1);
        if (count>0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
    }
    @Test
    public void test5() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService userService=(SysUserService) context.getBean("supplierService");
        userService.delete(1);
    }
    @Test
    public void test6() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SupplierService supplierService=(SupplierService) context.getBean("supplierService");
        Supplier supplier=new Supplier();
        supplier.setId(1L);
        supplier.setSupName("李轩");
        Integer count=supplierService.update(supplier);
        if (count>0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
    }
    @Test
    public void test7() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        StorageService storageService=(StorageService) context.getBean("storageService");
        StorageRecord storageRecord=new StorageRecord();
        storageRecord.setSrCode("李轩");
        storageService.insert(storageRecord);
    }
    @Test
    public void test8() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        StorageService storageService=(StorageService) context.getBean("storageService");
        storageService.delete(1);
    }
    @Test
    public void test9() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        StorageService storageService=(StorageService) context.getBean("storageService");
        StorageRecord storageRecord=new StorageRecord();
        storageRecord.setSrCode("李轩1");
        storageService.update(storageRecord);
    }
}
